package com.example.game_dafangdaxie.algorithm;

import com.example.game_dafangdaxie.StringConstant.PIECE;
import com.example.game_dafangdaxie.StringConstant.TouchXY;
import com.example.game_dafangdaxie.StringConstant.WINSTATUS;

import java.util.ArrayList;

public class JudgmentWin {
    public static int JudgmentWin(ArrayList<TouchXY> touchXYArrayList){
        int redPieces=0;
        int bluePieces=0;
        int allNum =touchXYArrayList.size();

        for(TouchXY t:touchXYArrayList){
            if(t.play== PIECE.RED){
                redPieces++;
            }
            if(t.play== PIECE.BLUE) {
                bluePieces++;
            }
        }
        if(allNum==36){
            redPieces=0;
            bluePieces=0;
            for(int i=0;i<allNum;i++){
                if(touchXYArrayList.get(i).play==0){
                    redPieces++;
                }else {
                    bluePieces++;
                }

            }
        }
        if(allNum<36){
            if(redPieces>18){
                return WINSTATUS.RED_WIN;
            }else if(bluePieces>18){
                return WINSTATUS.BLUE_WIN;
            }else {
                return WINSTATUS.NO_END;
            }
        }else if(redPieces>bluePieces){
            return WINSTATUS.RED_WIN;
        }else if(redPieces<bluePieces){
            return WINSTATUS.BLUE_WIN;
        }else {
            return WINSTATUS.DRAW;
        }
    }
}
